<template>
  <div class="rank">
    <!-- MET 榜 -->
    <div class="rank-f">
      <div class="title fs-36">MET榜</div>
      <div
        class="list"
        v-for="item in array"
        :key="item.id"
        @click="toSongSheet(item.list_category_name,item.id)"
        v-show="hasData"
      >
        <div class="left">
          <img :src="item.list_category_photo" alt />
        </div>
        <div class="right">
          <div class="top">
            <span class="left-t fs-32">{{item.list_category_name}}</span>
            <span class="right-t fs-24">每天更新</span>
          </div>
          <div class="bottom">
            <div
              class="item-list fs-26"
              v-for="res in item.itemList"
              :key="res.id"
            >{{res.index}}.&nbsp;{{res.music_name}}-{{res.singer_name[0]}}</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 推荐榜 -->
    <!-- 全球榜 -->
    <div class="rank-o">
      <div class="itemOption" v-for="item in optionList" :key="item.id">
        <div class="tit fs-36">{{item.list_category_name}}</div>
        <div class="list">
          <div
            class="itemList"
            v-for="items in item.son"
            :key="items.id"
            @click="toSongSheet(item.list_category_name,items.id)"
          >
            <div class="img">
              <img :src="items.list_category_photo" alt />
            </div>
            <span class="text fs-32">{{items.list_category_name}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { get } from "http";
export default {
  name: "rank",
  data() {
    return {
      title: "排行榜",
      rankList: {},
      optionList: [],
      itemList: [],
      hasData:false,
      array:[]
    };
  },
  components: {},
  methods: {
    // 获取排行榜分类
    getClassify() {
      const url = this.$host1 + `home/showRankingList`;
      this.$axios
        .get(url)
        .then(res => {
          if (res.data.code == 200) {
            this.rankList = res.data.result[0];
            this.optionList.push(res.data.result[1]);
            this.optionList.push(res.data.result[2]);
            var name1 = "热歌榜";
            var name2 = "新歌榜";
            var name3 = "畅销榜";
            var name4 = "原创榜";
            this.getRankList(1, name1);
            this.getRankList(2, name2);
            this.getRankList(3, name3);
            this.getRankList(4, name4);
          } else {
            this.AlertWin(res.data.message);
          }
        })
        .catch(err => {
          console.log(err, "err-----");
        });
    },
    // 获取MET榜的数据
    getRankList(type, name) {
      var array1 = [];
      var array2 = [];
      var array3 = [];
      var array4 = [];
      var type = type;
      var list_name = name;
      const url =
        this.$host1 +
        `home/metRankingList?list_name=` +
        list_name +
        `&type=` +
        type;
      this.$axios
        .get(url)
        .then(res => {
          //console.log(res.data, "---res.data--");
          if (res.data.code == 200) {
            if (res.data.data.list.length > 0) {
              res.data.data.list.map((item, index) => {
                item.index = index + 1;
                //this.rankList.itemList = [];
                //console.log(item,'--item');
                if (type == 1) {
                  //console.log(item, "item===");
                  //console.log(index, "---index");
                  if (index <= 2) {
                    array1.push(item);
                  }
                } else if (type == 2) {
                  if (index <= 2) {
                    array2.push(item);
                  }
                } else if (type == 3) {
                  if (index <= 2) {
                    array3.push(item);
                  }
                } else if (type == 4) {
                  if (index <= 2) {
                    array4.push(item);
                  }
                }

                //  var array2=[]
                //  array2.push(item)
                //  console.log(array2)
                //  var array3=[]
                //  array3.push(item)
                //  console.log(array3)
                //  var array4=[]
                //  array4.push(item)
                // console.log(array4)
                if (index <= 2) {
                  if (type == 1) {
                    this.rankList.son[0].itemList = array1;
                  } else if (type == 2) {
                    this.rankList.son[1].itemList = array2;
                  } else if (type == 3) {
                    //console.log(item,'--item3');
                    this.rankList.son[3].itemList = array3;
                  } else if (type == 4) {
                    this.rankList.son[2].itemList = array4;
                  }
                }
              });
              // this.itemList.push(this.itemList1);
              // this.itemList.push(this.itemList2);
              // this.itemList.push(this.itemList3);
              // this.itemList.push(this.itemList4);
              this.array = this.rankList.son;
              this.$forceUpdate();
            }
            //console.log(array1)
            this.hasData = true;
          } else {
            this.AlertWin(res.data.message);
          }
        })
        .catch(err => {
          console.log(err, "err-----");
        });
    },
    // 去排行榜首页
    toSongSheet(name, id) {
      //console.log(name,'---name');
      window.sessionStorage.setItem("findStatus", JSON.stringify(3));
      this.$router.push({
        path: "/index/song-sheet",
        query: { id: id, sheetStatus: 3, name: name }
      });
    }
  },
  created() {
    this.getClassify();
    
    
  },
  mounted() {

  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.rank {
  padding: 0 0 0.3rem;
  box-sizing: border-box;
  .rank-f {
    background-color: #fff;
    padding: 0.37rem 0.25rem 0.3rem;
    box-sizing: border-box;
    .title {
      font-weight: 800;
      color: rgba(68, 68, 68, 1);
      line-height: 0.32rem;
    }
    .list {
      display: flex;
      flex-direction: row;
      margin-top: 0.32rem;
      margin-bottom: 0.26rem;
      .left {
        margin-right: 0.35rem;
        width: 2.2rem;
        height: 2.2rem;
        img {
          height: 100%;
          border-radius: 0.16rem;
        }
      }
      .right {
        width: 100%;
        .top {
          margin-top: 0.16rem;
          overflow: hidden;
          height: 0.32rem;
          margin-bottom: 0.26rem;
          .left-t {
            float: left;
            height: 0.32rem;
            font-weight: 800;
            color: rgba(68, 68, 68, 1);
            line-height: 0.32rem;
          }
          .right-t {
            float: right;
            font-weight: 500;
            color: rgba(153, 153, 153, 1);
            line-height: 0.32rem;
          }
        }
        .bottom {
          .item-list {
            max-width: 3.95rem;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 1; //设置行数，1超出一行...，2超出两行...
            -webkit-box-orient: vertical;
            font-family: PingFang-SC-Medium;
            font-weight: 500;
            color: rgba(102, 102, 102, 1);
            line-height: 0.32rem;
            margin-bottom: 0.22rem;
          }
        }
      }
    }
  }
  .rank-o {
    width: 100%;
    margin-top: 0.22rem;
    .itemOption {
      padding: 0.43rem 0.23rem 0.43rem 0.25rem;
      box-sizing: border-box;
      background-color: #fff;
      margin-bottom: 0.22rem;
      .tit {
        font-weight: 800;
        color: rgba(68, 68, 68, 1);
        line-height: 0.32rem;
        margin-bottom: 0.35rem;
      }
      .list {
        display: flex;
        flex-wrap: wrap;
        flex-direction: row;
        justify-content: flex-start;
        .itemList {
          width: 2.2rem;
          text-align: center;
          margin-bottom: 0.32rem;
          margin-right: 0.14rem;
          .img {
            width: 2.2rem;
            margin-bottom: 0.22rem;
            border-radius: 0.16rem;
            overflow: hidden;
            img {
              width: 100%;
              display: block;
            }
          }
          .text {
            width: 100%;
            font-weight: 800;
            color: rgba(68, 68, 68, 1);
            line-height: 0.32rem;
          }
        }
      }
    }
  }
}
</style>
